package com.aube.plugin.rank.model;

import com.huyn.baseframework.model.Character;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by huyaonan on 16/8/9.
 */
public class RankModel implements Serializable {

    public String type;
    public String desc;
    public String week;
    public String pic;

    public String actorIds;

    public List<CharacterProxy> characters;

    public String getGroupKey() {
        return type + "-" + week;
    }

    public int getVotedNum() {
        if(characters == null)
            return 0;
        int i=0;
        for(Character character : characters)
            i+=character.weekPraiseCount;

        return i;
    }

    /**
     * 降序排序
     * @return
     */
    public RankModel sort() {
        if(characters != null)
            Collections.sort(characters, new Comparator<Character>() {
                @Override
                public int compare(Character lhs, Character rhs) {
                    if(lhs.praiseCount > rhs.praiseCount)
                        return -1;
                    else if(lhs.praiseCount < rhs.praiseCount)
                        return 1;
                    return 0;
                }
            });
        return this;
    }

}
